package com.efeichong.common.security;

import com.efeichong.common.domain.ResponseData;
import com.efeichong.common.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author lxk
 * @date 2020/9/4
 * @description 登录信息认证失败统一处理
 */
@Slf4j
public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) {
        log.warn("认证失败:" + request.getRequestURI(), authException);
        ResponseUtils.format(response, request, ResponseData.loginExpire());
    }
}
